#include<stdio.h>
int main()
{
	int n,num,i=0,flag[10000]={0},j;
	int by[11]={0,1,0,1,0,1,0,1,1};
	scanf("%d",&n);
	while(n--)
	{
		getchar();
		scanf("%d",&num);
		if(by[num-1]==1 || by[num-3]==1 || by[num-7]==1 || by[num-8]==1)
		{
			flag[i]=1;i++;
		}
		else
		{
			flag[i]=0;i++;
		}
			
	}
	for(j=0;j<i;j++)
		printf("%d\n",flag[j]);
	return 0;
}
